try_call

function try_call(fn: () -> unit): boolean

Calls a function that doesn't return a value and handles exceptions gracefully.

Return

true if call succeeds, false otherwise.

Since

0.13.0

Parameters

fn

The function to be called.


function <T> try_call(fn: () -> T): T?

Calls a function and handles exceptions gracefully, returning null if an exception occurs.

Return

T if call succeeds, null otherwise.

Since

0.13.0

Parameters

fn

The function to be called.


function <T> try_call(fn: () -> T, default: T): T

Calls a function and handles exceptions gracefully, providing a fallback value if an exception occurs.

Return

T if call succeeds and the supplied default value otherwise.

Since

0.13.0

Parameters

fn

The function to be called.

default

The fallback value to be returned if an exception occurs.